//
//  Model.swift
//  eBooks
//
//  Created by JunMing on 2019/10/11.
//  Copyright © 2019 赵俊明. All rights reserved.
//

import UIKit

class Model: Codable {
    /// 完整文件名,带epub
    var fullname:String!
    var author:String?
    var desc:String?
    var cover:String?
    var date:String?
    /// 所属的类型，小说，文学，传记等
    var booktype:String?
    
    /// 文件大小，实际大小
    var filesize:String?
    
    /// 状态量
    var isdel:Bool = true
    var isSave:Bool = false
    var totalTime:Int = 0
    
    /// 阅读进度
    var readRate:String?
    
    init(_ name:String, _ size:String?) {
        filesize = size
        fullname = name
    }
    
    /// 完整epub文件路径
    func bookurl() -> String {
        return Tools.hostName("epubs/"+fullname!)
    }
    
    /// 完整封面路径
    func coverurl() -> String {
        return Tools.hostName("covers/"+cover!)
    }
    
    /// 完整封面路径
    func sizeStr() -> String? {
        print(Int(filesize!) as Any)
        guard let datasize = filesize,let sumSize = NSInteger(datasize) else {
            return nil
        }
        return FileHelper.transBytes(sumSize)
    }
    
    /// 不带.epub、书名号的标题
    func title() -> String? {
        let name = fullname?.replacingOccurrences(of: ".epub", with: "")
        return name?.replacingOccurrences(of: "《", with: "").replacingOccurrences(of: "》", with: "")
    }
    
    /// 带书名号,不带.epub的标题
    func fullTitle() -> String? {
        guard let title = title() else { return nil }
        return "《"+title+"》"
    }
    
    /// 文件类型，都是epub，这里没啥用
    func filetype() -> String? {
        return "epub"//fullname?.split(separator: ".").last as String
    }
    
    /// 本地文件路径
    func localPath() -> String {
        return Tools.documentPath()!+"/"+fullname!
    }
    
    /// 本地文件路径
    func rateDesc() -> String {
        guard let rateStr = readRate  else { return "貌似还没开始读哦，行动起来" }
        guard let rate = Double(rateStr) else { return "貌似还没开始读哦，行动起来" }
        var rateDesc = ""
        if rate < 30.0 {
            rateDesc = "虽然已经开始阅读，但我需要加油呀"
        }else if rate > 30.0 && rate < 50.0 {
            rateDesc = "马上读过半了，我要再接再厉"
        }else if rate > 50.0 && rate < 80.0 {
            rateDesc = "超过一半啦，一鼓作气读完它"
        }else if rate > 80.0 && rate < 90.0 {
            rateDesc = "快要读完啦，胜利就在眼前啦"
        }else {
            rateDesc = "你太棒了，马上快要读完啦"
        }
        return rateDesc
    }
}

class SetHeaderModel: NSObject {
    var items = [SetModel]()
    var title:String?
    var icon:String?
    init(_ icon:String?, _ title:String?) {
        self.icon = icon
        self.title = title
    }
}

class SetModel: NSObject {
    var icon:String?
    var title:String?
    var accType:String?
    var adType:String?
    var pushVC:String?
    
    init(_ icon:String?, _ title:String?, _ accType:String?, _ adType:String?) {
        self.icon = icon
        self.title = title
        self.accType = accType
        self.adType = adType
    }
}
